/*
 * @Autor: Ruohong Yu
 * @Date: 2023-03-31 14:50:31
 * @Description: file content
 * @FilePath: \ebook\src\api\user.js
 */
import axios from 'axios'

export function login (name, pwd) {
  return axios({
    method: 'post',
    url: `${process.env.VUE_APP_BOOK_URL}/login`,
    data: {
      username: name,
      password: pwd
    }
  })
}

export function register (name, pwd, ema) {
  return axios({
    method: 'post',
    url: `${process.env.VUE_APP_BOOK_URL}/register`,
    data: {
      username: name,
      password: pwd,
      email: ema
    }
  })
}

export function modifyUser (rename, name, ema) {
  return axios({
    method: 'post',
    url: `${process.env.VUE_APP_BOOK_URL}/my/userinfo`,
    data: {
      reusername: rename,
      username: name,
      email: ema
    }
  })
}

export function modifyPwd (email, emailcode, pwd) {
  return axios({
    method: 'post',
    url: `${process.env.VUE_APP_BOOK_URL}/updatepwd`,
    data: {
      email,
      emailcode,
      password: pwd
    }
  })
}

export function sendEmailCode (ema) {
  return axios({
    method: 'post',
    url: `${process.env.VUE_APP_BOOK_URL}/sendemailcode`,
    data: {
      email: ema
    }
  })
}

export function updateUserAvatar (username, f) {
  return axios({
    method: 'post',
    url: `${process.env.VUE_APP_BOOK_URL}/my/update/avatar`,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: {
      username,
      file: f
    }
  })
}
